package edu.zjucst.spb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import edu.zjucst.spb.dao.role.RoleDao;
import edu.zjucst.spb.domain.entity.Role;
import edu.zjucst.spb.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;

    @Override
    @Transactional
    public List<Role> findRole(Role role) {
//        SelectStatementProvider selectStatement = SqlBuilder.select(roleMapper.selectList)
//            .from(tbRole)
//            .build()
//            .render(RenderingStrategies.MYBATIS3);
//
//        return roleMapper.selectMany(selectStatement);
        return roleDao.selectList(new LambdaQueryWrapper<Role>()
            .eq(Role::getId, role.getId())
            .eq(Role::getRoleName, role.getRoleName())
        );
    }

    @Override
    public Role findRoleById(Long Id) {
        return roleDao.selectOne(new LambdaQueryWrapper<Role>()
            .eq(Role::getId, Id)
        );
    }
}
